﻿@{
    Layout = null;
}
@using LY.Manage.Model;
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>为用户分配权限</title>
    <!--引入文件-->
    <link href="~/Content/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.8.2.min.js"></script>
    <script src="~/Scripts/jquery.easyui.min.js"></script>
    <script src="~/Scripts/easyui-lang-zh_CN.js"></script>
    <script src="~/Scripts/datapattern.js"></script>
    <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <link href="~/Content/tableStyle.css" rel="stylesheet" />



</head>
<body>
    <div>
        为用户@{
            UserInfo userInfo = ViewBag.UserInfo;
            <span style="font-size:14px;color:red;font-weight:bold">@userInfo.UName</span>
        }分配权限<br />
        <table>
            <tr><th>编号</th><th>权限名称</th><th>Url</th><th>HttpMethod</th><th>操作</th></tr>
            @{
                List<ActionInfo> allActionList = ViewBag.AllActionList;
                List<R_UserInfo_ActionInfo> allActionId = ViewBag.AllActionIdList;
                foreach (var item in allActionList)
                {
                    var actionName = "cba_" + item.ID;
                    var noactionName = "nocba_" + item.ID;
                    <tr>
                        <td>@item.ID</td>
                        <td>@item.ActionInfoName</td>
                        <td>@item.Url</td>
                        <td>@item.HttpMethod</td>
                        <td>
                            @{
                    var isExt = (from a in allActionId
                                 where a.ActionInfoID == item.ID
                                 select a).FirstOrDefault();
                    if (isExt != null)
                    {
                        if (isExt.IsPass)
                        {
                            <label for="@actionName">允许</label>
                                <input type="radio" checked="checked" value="true"
                                       class="selectActions" ids="@item.ID"
                                       id="@actionName"
                                       name="@actionName" />

                                <label for="@noactionName">禁止</label>
    <input type="radio" value="false"
           class="selectActions" ids="@item.ID"
           id="@noactionName"
           name="@actionName" />

                        }
                        else
                        {
                            <label for="@actionName">允许</label>
                                <input type="radio" value="true"
                                       class="selectActions" ids="@item.ID"
                                       id="@actionName"
                                       name="@actionName" />

                                <label for="@noactionName">禁止</label>
    <input type="radio" value="false"
           checked="checked"
           class="selectActions" ids="@item.ID"
           id="@noactionName"
           name="@actionName" />
                        }
                    }
                    else
                    {
                        <label for="@actionName">允许</label>
                                <input type="radio" value="true"
                                       class="selectActions" ids="@item.ID"
                                       id="@actionName"
                                       name="@actionName" />

                                <label for="@noactionName">禁止</label>
                                <input type="radio" value="false"                                       
                                       class="selectActions" ids="@item.ID"
                                       id="@noactionName"
                                       name="@actionName" />
                    }

                    <input value="清除"  type="button" class="btnClear" ids="@item.ID"/>
                            }

                        </td>
                    </tr>
                }
            }

        </table>

    </div>
</body>
</html>

<script type="text/javascript">
    $(function () {
        bindRadioClickEvent();
        bindBtnClearClickEvent();

    });

    //清除权限
    function bindBtnClearClickEvent()
    {
        $(".btnClear").click(function () {
            var actionId = $(this).attr("ids");//获取权限编号
            var isPass = $(this).val();
            var $control = $(this);
            $.post("/UserInfo/ClearUserAction", { "actionId": actionId, "userId": '@userInfo.ID', "isPass": isPass }, function (data) {
                var serverData = data.split(':');
                if (serverData [0]== "ok")
                {
                    //让他单选按钮处于未选中状态

                    $control.parent().find(".selectActions").removeAttr("checked");

                    ShowMsg(serverData[1]);

                }
                else
                {

                    ShowMsg(serverData[1]);
                }

            });

            function ShowMsg(msg)
            {
                $.messager.show({
                    title: '提示',
                    msg: msg,
                    showType: 'show'
                });
            }
        });
    }

    //点击单选按钮完成权限的分配
    function bindRadioClickEvent()
    {
        $(".selectActions").click(function () {
            var actionId = $(this).attr("ids");//获取权限编号
            var isPass=$(this).val();
            $.post("/UserInfo/SetUserAction", {"actionId":actionId,"userId":'@userInfo.ID',"isPass":isPass}, function (data) {
                if (data=="ok")
                {
                    $.messager.show({
                        title:'提示',
                        msg:'权限分配成功',
                        showType:'show'
                    });

                }
                else
                {
                    $.messager.show({
                        title:'提示',
                        msg:'权限分配失败',
                        showType:'show'
                    });
                }

            });
        });
    }

</script>